


//
//  RelayDetailViewController.m
//  nncloud
//
//  Created by macfeel on 2019/5/14.
//  Copyright © 2019 macfai. All rights reserved.
//
#import "PrintViewController.h"
#import "RelayDetailViewController.h"
#import "EidtViewController.h"
@interface RelayDetailViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>

@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSArray *nameArray;

@property (nonatomic,strong)NSMutableArray *titleArray;

@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,assign)NSInteger currentPage;

@property (nonatomic,strong)NSDictionary *dict;

@end


@implementation RelayDetailViewController

#define cellIdentifier  @"relayd"
//#define HeaderHight  290
#define PageSize 20

-(UITableView *)tableView{
    
    if (!_tableView) {
        
//        WeakStament(ws);
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight -NavBarHeight-45) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 55;
        //        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = kBackgroundColor;
//        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
        //        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //            [ws loadData];
        //        }];
        //        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //            [ws loadMoreData];
        //        }];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}

- (void)viewDidLoad {
    
    ///**************************
    ///继电器转辙机综合器材  设备信息详情共用这个页面
    [super viewDidLoad];
    self.dataArray = [NSMutableArray array];
    self.titleArray = [NSMutableArray array];
    ///设备信息
    [self.navigationItem setItemWithTitle:@"设备信息" textColor:kNavigationTitleColor fontSize:18 itemType:center];
//    if ([[NUserModel shareInstance].equipType isEqualToString:@"camel"]) {
//        [self addNavgationRightButtonWithFrame:CGRectMake(0, 0, 30, 30) title:@"" Image:@"" selectedIMG:@"" tartget:self action:@selector(editAction)];
//    }else{
        [self addNavgationRightButtonWithFrame:CGRectMake(0, 0, 30, 30) title:@"编辑" Image:@"" selectedIMG:@"" tartget:self action:@selector(editAction)];
//    }
    

    [self.view addSubview:self.tableView];
    ///打印标签
    [self addBottomBuyView];
    ///
    [self formData];
}

-(void)formData{
    
    NSDictionary *dict;
    
    if (self.model) {
        ///传过来的模型转成字典
        dict = [self.model mj_keyValues];
        YYLog(@"为什么这么少heheh:%@",dict);
        self.dict = dict;
        YYLog(@"%@",dict);
    }
    
    
    ///直接传字典的处理方式，这种方式有问题，在分页时候会报错
    NSArray *dictArray = [dict allKeys];
    self.titleArray = [dictArray copy];
//    NSDictionary *dict = self.dict;
    for (int i=0; i<[dict allKeys].count; i++) {
        NSString *key = dictArray[i];
        NSString *value = [dict objectForKey:key];
        //处理null
        if ([value isKindOfClass:[NSNull class]]) {
            value = @"";
        }
        //处理返回的int 类型  因为赋值时候需要进行字符串赋值
        if ([value isKindOfClass:[NSNumber class]]) {
            value = [NSString stringWithFormat:@"%@",value];
        }
        [self.dataArray addObject:value];
    }
    [self.tableView reloadData];
}

#pragma mark - 编辑
-(void)editAction{
    EidtViewController *edt = [[EidtViewController alloc]init];
    //编辑时将字典传到下个页面
    edt.dict = self.dict;
    [self.navigationController pushViewController:edt animated:YES];
}

#pragma mark - 底部复制添加和打印标签
#define BarHeight 45.f
///添加底部购买bar
- (void)addBottomBuyView{
    
    UIButton *cartBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cartBtn.frame = CGRectMake(0, ScreenHeight-BarHeight-NavBarHeight, ScreenWidth, BarHeight);
    cartBtn.backgroundColor = kSystemtBlue;
    [cartBtn addTarget:self action:@selector(printAction) forControlEvents:UIControlEventTouchUpInside];
    [cartBtn setTitle:@"打印标签" forState:UIControlStateNormal];
    [self.view addSubview:cartBtn];
    
    
}


#pragma mark - 打印标签
///打印
-(void)printAction{
    
    PrintViewController *print = [PrintViewController new];
    [self.navigationController pushViewController:print animated:YES];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//        return self.nameArray.count;
    NSDictionary *dict = self.dict;
    return [dict allKeys].count;
//    return self.nameArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    // Configure the cell...
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1
                                      reuseIdentifier: cellIdentifier];
    }
    
//    NSDictionary *noteDictionary = [self.notes objectAtIndex: indexPath.row];
//    cell.textLabel.text = noteDictionary[@"title"];
//    cell.detailTextLabel.text = [self.dates objectAtIndex: indexPath.row];
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.selectionStyle = 0;
    cell.textLabel.textColor = kDarkGrayColor;
//    cell.textLabel.text = self.nameArray[indexPath.row];
    cell.textLabel.text = self.titleArray[indexPath.row];
    cell.detailTextLabel.text = self.dataArray[indexPath.row];
//    cell.detailTextLabel.text = @"详情";
    
    return cell;
}




@end


//if ([self.flag isEqualToString:@"r"]) {
//    self.nameArray = @[@"预检员",@"报废执行人",@"临时验收人",@"验收员",@"执行报废日期",@"验收日期",@"出所日期",@"禁用日期",@"合格证号",@"入所次数",@"周期",@"报废日期",@"检修员",@"备注",@"用途",@"出所类型",@"任务分配日期",@"站名",@"入待修库日期",@"上道日期",@"检修日期",@"测试数据表编号",@"是否工程",@"外单位",@"数据日志",@"预检日期",@"成品库状态",@"厂编号",@"验收次数",@"使用处所",@"出厂日期",@"sid",@"成品库位置",@"故障测试人",@"故障测试日期",@"剩余寿命",@"首次出所日期",@"生产厂家",@"到期日期",@"抽验日期",@"段编号",@"物资编码",@"待修库状态",@"抽验员",@"待修库位置",@"是否核算",@"器材种类",@"选定项",@"状态",@"入所日期",@"互验员",@"轮修次数",@"禁用原因",@"旧编号",@"返所原因",@"复验日期",@"临时检修人",@"报废原因",@"型号",@"组合位置",@"入成品库日期",@"处理意见",];
//
//}else if ([self.flag isEqualToString:@"t"]){
//    self.nameArray = @[@"段编号",@"型号",@"生产厂家",@"出所日期",@"到期日期",@"去向",@"岔号",@"牵引名称",@"线制",@"开向",@"表示杆特征",@"设备老编号",@"出厂编号",@"出厂日期",@"检修日期",@"验收日期",@"整机检修人",@"整机眼收人",];
//}else{
//
//    self.nameArray = @[@"型号",@"生产厂家",@"厂编号",@"站名",@"周期",@"组合位置",@"使用处所",@"用途",@"入所次数",@"返所原因",@"验收次数",@"出厂日期",@"报废日期",@"入所日期",@"检修日期",@"验收日期",@"出所日期",@"到期日期",@"上道日期",@"预检员",@"验收员",@"互验员",@"器材种类",@"检修员",@"状态",@"抽验员",@"测试数据表编号",];
//}
